package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.wf.bi.web.form.WfViewCustomConfigForm;
import com.augurit.wf.common.entity.WfViewCustomConfig;

public class WfViewCustomConfigConvertor {
	public static WfViewCustomConfigForm convertVoToForm(WfViewCustomConfig entity) {
		if(entity != null) {
			WfViewCustomConfigForm form = new WfViewCustomConfigForm();
			form.setId(entity.getId());
			form.setTemplateCode(entity.getTemplateCode());
			form.setUserKey(entity.getUserKey());
			form.setCustomQueryCondition(entity.getCustomQueryCondition());
			form.setCustomGroupProperty(entity.getCustomGroupProperty());
			form.setCustomOrderProperty(entity.getCustomOrderProperty());
			form.setCustomOrderby(entity.getCustomOrderby());
			form.setCustomMemo(entity.getCustomMemo());
			form.setCustomExecHql(entity.getCustomExecHql());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfViewCustomConfigForm form, WfViewCustomConfig entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getTemplateCode() != null && form.getTemplateCode().trim().length() > 0)
				entity.setTemplateCode(form.getTemplateCode().trim());
			if(form.getUserKey() != null && form.getUserKey().trim().length() > 0)
				entity.setUserKey(form.getUserKey().trim());
			if(form.getCustomQueryCondition() != null && form.getCustomQueryCondition().trim().length() > 0)
				entity.setCustomQueryCondition(form.getCustomQueryCondition().trim());
			if(form.getCustomGroupProperty() != null && form.getCustomGroupProperty().trim().length() > 0)
				entity.setCustomGroupProperty(form.getCustomGroupProperty().trim());
			if(form.getCustomOrderProperty() != null && form.getCustomOrderProperty().trim().length() > 0)
				entity.setCustomOrderProperty(form.getCustomOrderProperty().trim());
			if(form.getCustomOrderby() != null && form.getCustomOrderby().trim().length() > 0)
				entity.setCustomOrderby(form.getCustomOrderby().trim());
			if(form.getCustomMemo() != null && form.getCustomMemo().trim().length() > 0)
				entity.setCustomMemo(form.getCustomMemo().trim());
			if(form.getCustomExecHql() != null && form.getCustomExecHql().trim().length() > 0)
				entity.setCustomExecHql(form.getCustomExecHql().trim());
		}
	}
	
	public static List<WfViewCustomConfigForm> convertVoListToFormList(List<WfViewCustomConfig> wfViewCustomConfigList) {
		if(wfViewCustomConfigList != null && wfViewCustomConfigList.size() > 0) {
			List<WfViewCustomConfigForm> wfViewCustomConfigFormList = new ArrayList();
			for(int i=0; i<wfViewCustomConfigList.size(); i++) {
				wfViewCustomConfigFormList.add(convertVoToForm(wfViewCustomConfigList.get(i)));
			}
			return wfViewCustomConfigFormList;
		}
		return null;
	}

	public static List<WfViewCustomConfig> convertFormListToVoList(List<WfViewCustomConfigForm> wfViewCustomConfigFormList) {
		if(wfViewCustomConfigFormList != null && wfViewCustomConfigFormList.size() > 0) {
			List<WfViewCustomConfig> wfViewCustomConfigList = new ArrayList();
			for(int i=0; i<wfViewCustomConfigFormList.size(); i++) {
				WfViewCustomConfig wfViewCustomConfig = new WfViewCustomConfig();
				convertFormToVo(wfViewCustomConfigFormList.get(i), wfViewCustomConfig);
				wfViewCustomConfigList.add(wfViewCustomConfig);
			}
			return wfViewCustomConfigList;
		}
		return null;
	}
}